<template>
  <div class="areaContainer">
    <div class="search">
      <el-input v-model.trim="searchValue" placeholder="请输入区域位置关键字进行查询" clearable :prefix-icon="Search" @keyup="getAreaList(searchValue)">
        <template #append>
          <el-button :icon="Search"  @click="getAreaList(searchValue)"/>
        </template>
      </el-input>
    </div>
    <el-table :data="logData" stripe style="width: 100%;margin-top: 10px;" height="50%"  :default-sort="{ prop: 'createTime', order: 'descending' }">
    <el-table-column prop="logId" label="日志ID" width="85"/>
     <el-table-column label="操作用户" width="110">
      <template #default="row">
        <div v-if="row.row.userId!=null">{{row.row.userId}}</div>
        <div v-else>fasle</div>
      </template>
    </el-table-column>
    <el-table-column label="操作管理员" width="110">
      <template #default="row">
        <div v-if="row.row.adminId!=null">{{row.row.adminId}}</div>
        <div v-else>fasle</div>
      </template>
    </el-table-column>
    <el-table-column prop="ipAddress" label="ip地址" />
    <el-table-column prop="content" label="操作内容" />
    <el-table-column prop="type" label="操作类型"  :filters="[{text: '添加',value: '添加'},{text: '删除',value: '删除'},{text: '修改',value: '修改'}]" :filter-method="filterType">
    </el-table-column>
    <el-table-column prop="success" label="是否成功">
      <template #default="row">
        <div v-if="row.row.success == '成功'"><el-button type="success" plain>成功</el-button></div>
        <div v-else><el-button type="danger" plain>失败</el-button></div>
      </template>
    </el-table-column>
   <el-table-column prop="createTime" label="创建时间" width="250" sortable>
      <template #default="row">
        <div>{{timeTuTIL.myTimeFormat(row.row.createTime)}}</div>
      </template>
    </el-table-column>  
    </el-table>
   <div class="pagination">
    <el-pagination v-model:current-page="page" v-model:page-size="size" :page-sizes="[5,10,20,30]" :small="small" :disabled="disabled"
      :background="background" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
  </div>
  </div>
</template>

<script setup>
import { reactive , inject , onMounted , ref } from "vue"
import axios from '../../axios/axiosInstance'
import timeTuTIL from '../../utils/timeUtilT'
import { ElLoading,ElMessage ,ElMessageBox} from 'element-plus'
import { Delete ,Edit,Search} from '@element-plus/icons-vue'

//变量定义

let logData = reactive([])
const total = ref(0)
let page = 1
let size = 5
const small = ref(false)
const background = ref(false)
const disabled = ref(false)

//方法 

const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
  size = val
  init()
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  page = val
  init()
}

 const clear = (value) => {
    Object.keys(value).map(key => {
      delete value[key]
    })
  }

const getAreaList = (searchValue) => {
  if(searchValue != ''){
    axios.get(`/parking-service/area/areaList/${searchValue}`).then((res) => {
        console.log(res)    
        if(res.code == 200){
          clear(areaData)
          for(let i in res.data){
            console.log(i)
            areaData.push(res.data[i])
          }
          ElMessage({type: "success",message: "查询成功"});
        }else{
          ElMessage({type: "error",message: "查询失败"});
       }
      }).catch((err) => {
        console.log(err)
      })
  }else{
    init()
  }
}

const filterType = (value, row) => {
  return row.type === value
}


const init = () => {
  const loading = ElLoading.service({
        lock: true,
        text: '拼命加载中',
          background: 'rgba(0, 0, 0, 0.7)',
      })
      setTimeout(() => {
        loading.close()
      }, 2000)
     axios.get(`/account-service/user-log/operationList/${page}/${size}`).then((res) => {   
      console.log("res为：")
      console.log(res)
      clear(logData)
      total.value = res.data.total
      for(let i in res.data.content){
        console.log(i)
        logData.push(res.data.content[i])
      }
      console.log("最后的logData是：")
      console.log(logData)
    }).catch((err) => {

      console.log(err)

    })
}

const getNameFilter = () => {
   axios.get('/parking-service/area/areaName').then((res) => {   
      console.log("res为：")
      console.log(res)
      console.log(total)
      for(let i in res.data){
        console.log(i)
        nameFilter.push(res.data[i])
      }
      console.log("最后的parkingData是：")
      console.log(nameFilter)
    }).catch((err) => {

      console.log(err)

    })
}

const getCategoryNameFilter = () => {
   axios.get('/parking-service/category/categoryName').then((res) => {   
      console.log("res为：")
      console.log(res)
      console.log(total)
      for(let i in res.data){
        console.log(i)
        categoryNameFilter.push(res.data[i])
      }
      console.log("最后的parkingData是：")
      console.log(categoryNameFilter)
    }).catch((err) => {

      console.log(err)

    })
}

//页面初始化方法
onMounted(()=>{ 
  init()
  getNameFilter()
  getCategoryNameFilter()
})
</script>

<style scoped>
.areaContainer .search{
  display: flex;
  width: 600px;
}
.areaContainer .pagination{
 justify-content: center;
 margin-top: 15px;
}

</style>
